package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.BizItem;
import com.ymatou.iapi.godmch.parameter.batchGetBizConfigBean;
import com.ymatou.iapi.godmch.parameter.setBizConfigBean;
import com.ymatou.iapi.godmch.service.batchGetBizConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.biz_config;
import com.ymttest.database.model.godmch.biz_configExample;
import com.ymttest.database.sqlwapper.godmch.biz_configWapper;
import com.ymttest.utils.TestDataManager;
/**
*批量获取业务配置参数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_batchGetBizConfig{
	private static batchGetBizConfigBean bean;
	private static batchGetBizConfigCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量获取业务配置参数");
	}

	@Before
	public void caseUp() {
		bean=new batchGetBizConfigBean();
		call=new batchGetBizConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchGetBizConfig_001() {
		Logger.start(true,"批量获取业务配置参数-都存存在的-修改");
		try {
			setBizConfigBean setBizConfigBean=GodmchManageCallService.initSetBizConfig();
			
	        Integer bizId=Integer.parseInt(TestDataManager.getRandomNum(5));
	        String key="key_"+TestDataManager.getRandomNum(5);
	        String value="value"+TestDataManager.getRandomNum(5);
			Map<String,String> map=new HashedMap();
			map.put(key, value);
			map.put(key+"_1", value+"_1");
			setBizConfigBean.setBizId(bizId);
			setBizConfigBean.setBizConfigMap(map);
				
			GodmchManageCallService.setBizConfig(setBizConfigBean);
			
			biz_configExample example=new biz_configExample();
			biz_configWapper bizWapper=new biz_configWapper();
			example.createCriteria().andBiz_idEqualTo(setBizConfigBean.getBizId());
			biz_config model= bizWapper.selectByExample(example).get(0);
			
			List<BizItem> lst=new ArrayList();
			BizItem item=new BizItem();
			item.setBizId(model.getBiz_id());
			item.setBizKey(model.getBiz_key());
			lst.add(item);
			bean.setBatchList(lst);
			call.setData(bean);
			call.callService();		
			
			example.createCriteria().andBiz_idEqualTo(setBizConfigBean.getBizId());
			model= bizWapper.selectByExample(example).get(0);
			Logger.verifyEquals(200, call.getStatusCode(), "验证status");
			BizItem bizItem=call.getBatchList().get(0);
			
			Logger.verifyEquals(bizItem.getBizId(), model.getBiz_id(), "验证数据库中的Biz_id与传入的一致");
			Logger.verifyEquals(bizItem.getBizKey(), model.getBiz_key(), "验证数据库中的Biz_key与传入的一致");
			Logger.verifyEquals(bizItem.getBizValue(), model.getBiz_value(), "验证数据库中的Biz_value与传入的一致");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}